//
//  UIView+Addition.m
//  BaseProject
//
//  Created by zhangrongbing on 2016/10/12.
//  Copyright © 2016年 lovcreate. All rights reserved.
//

#import "UIView+Addition.h"

@implementation UIView (Addition)

-(void)setLc_x:(CGFloat)lc_x{
    CGRect frame = self.frame;
    frame.origin.x = lc_x;
    self.frame = frame;
}

-(CGFloat)lc_x{
    return self.frame.origin.x;
}

-(void)setLc_y:(CGFloat)lc_y{
    CGRect frame = self.frame;
    frame.origin.y = lc_y;
    self.frame = frame;
}

-(CGFloat)lc_y{
    return self.frame.origin.y;
}

-(void)setLc_w:(CGFloat)lc_w{
    CGRect frame = self.frame;
    frame.size.width = lc_w;
    self.frame = frame;
}

-(CGFloat)lc_w{
    return self.frame.size.width;
}

-(void)setLc_h:(CGFloat)lc_h{
    CGRect frame = self.frame;
    frame.size.height = lc_h;
    self.frame = frame;
}

-(CGFloat)lc_h{
    return self.frame.size.height;
}

-(void)setLc_size:(CGSize)lc_size{
    CGRect frame = self.frame;
    frame.size = lc_size;
    self.frame = frame;
}

-(CGSize)lc_size{
    return self.frame.size;
}

-(void)setLc_origin:(CGPoint)lc_origin{
    CGRect frame = self.frame;
    frame.origin = lc_origin;
    self.frame = frame;
}

-(CGPoint)lc_origin{
    return self.frame.origin;
}

-(CGPoint)lc_center{
    return self.center;
}

-(void)setLc_center:(CGPoint)lc_center{
    CGPoint point = self.center;
    point.x = lc_center.x;
    point.y = lc_center.y;
    self.center = point;
}

static char LoadingViewKey = '\0';
-(void)setLc_loadingView:(LoadingView *)lc_loadingView{
    NSAssert(lc_loadingView, @"loadingView is not nil");
    if (lc_loadingView != self.lc_loadingView) {
        // 删除旧的，添加新的
        [self.lc_loadingView removeFromSuperview];
//        [self addSubview:lc_loadingView];
        objc_setAssociatedObject(self, &LoadingViewKey, lc_loadingView, OBJC_ASSOCIATION_ASSIGN);
    }
}

-(LoadingView*)lc_loadingView{
    return objc_getAssociatedObject(self, &LoadingViewKey);
}

-(void)lc_showToastMessage:(NSString*)message{
    UIApplication* application = [UIApplication sharedApplication];
    MBProgressHUD* toastHud ;
    if (!toastHud) {
        toastHud = [[MBProgressHUD alloc] initWithView:application.keyWindow];
        toastHud.removeFromSuperViewOnHide = YES;
    }
    toastHud.mode = MBProgressHUDModeText;
    toastHud.label.text = message;
    toastHud.offset = CGPointMake(0, MBProgressMaxOffset);
    [application.keyWindow addSubview:toastHud];
    [toastHud showAnimated:YES];
    [toastHud hideAnimated:YES afterDelay:1];
}

-(MBProgressHUD*)lc_showHUD{
    UIApplication* application = [UIApplication sharedApplication];
    MBProgressHUD* hud = [[MBProgressHUD alloc] initWithFrame:application.keyWindow.bounds];
    hud.removeFromSuperViewOnHide = YES;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.backgroundView.color = [[UIColor grayColor] colorWithAlphaComponent:.4];
    hud.mode = MBProgressHUDModeIndeterminate;
    [application.keyWindow addSubview:hud];
    [hud showAnimated:YES];
    return hud;
}
@end
